import java.util.LinkedList;
import java.util.Queue;

public class SerializeAndReconstructTree {
    private static class Node{
        int value;
        Node left;
        Node right;
        Node(int v){
            value = v;
        }
    }

    public static Queue<String> preSerial(Node head){
        Queue<String> ans = new LinkedList<>();
        pres(head, ans);
        return ans;
    }

    public static void pres(Node head, Queue<String> ans){
        if (head == null){
            ans.add(null);
        } else {
            ans.add(String.valueOf(head.value));
            pres(head.left, ans);
            pres(head.right, ans);
        }
    }

    public static void main(String[] args) {
        Node head = new Node(1);
        head.left = new Node(2);
        head.right = new Node(3);
        head.left.left = new Node(4);
        head.left.right = new Node(5);
        head.right.left = new Node(6);
        head.right.right = new Node(7);

        Queue<String> queue = preSerial(head);
        System.out.println(queue);
    }

}
